<?php include('header.php'); ?>
<?php include('side.php'); ?>
<div class="layui-body">
	<div style="text-align:center; padding: 100px 30px;">
		<div class="layui-input-inline">
			<input type="text" name="token" lay-verify="token" size="6" autocomplete="off" class="layui-input" maxlength="4" style="background: #F8F8F8; font-size: 100px; padding: 80px 20px 80px 80px; color: #0C0; letter-spacing:30px;">
		</div>
	</div>
</div>

<script>
layui.use('layer', function() {
	var layer = layui.layer;
	
	$('input[name="token"]').bind('blur', function() {
		var othis = $(this);
		var len = othis.val().length;
		
		
		var btnText = {
			confirm: '确认验证',
			unconfirm: '取消验证',
			close: '关闭',
			lock: '确认锁定',
			unlock: '取消锁定'
		}
		
		
			if (len == 4) {
				windos.ajaxPost('/site/get_profile', {t: othis.val()}, function(res) {
					var btnText1 = res.data.status == 1 ? btnText.unconfirm : btnText.confirm;
					var btnText2 = btnText.close;
					var btnText3 = res.data.status == 2 ? btnText.unlock : btnText.lock;
					var btns = [btnText1, btnText2, btnText3];
					if (typeof(res.data) === 'object') {
						var open = false;
						layer.open({
							type: 1,
							offset: 'auto',
							id: 'view',
							area: ['360px', '480px'], //宽高
							shade: 0,
							closeBtn: false,
							btn: btns,
							btnAlign: 'c',
							title: '个人资料',
							content: '<table class="layui-table" lay-skin="line">\
							<colgroup><col width="30%"><col width="70%"></colgroup>\
							<tbody>\
								<tr><td align="right">姓名：</td><td>' + windos.formatText(res.data.name) + '</td></tr>\
								<tr style="display: none"><td align="right">性别：</td><td>' + (res.data.gender ? '男' : '女') + '</td></tr>\
								<tr><td align="right">桌号：</td><td>' + windos.formatText(res.data.tnumber, 0) + '</td></tr>\
								<tr><td align="right">手机号：</td><td>' + windos.formatMobile(res.data.mobile, 0) + '</td></tr>\
								<tr><td align="right">邀请人：</td><td>' + windos.formatText(res.data.inviter) + '</td></tr>\
								<tr><td align="right">当前状态：</td><td>' + formatStatus(res.data.status) + '</td></tr>\
								<tr><td align="right">邀请码：</td><td>' + res.data.token + '</td></tr>\
								<tr><td align="right">操作时间：</td><td>' + windos.formatDate(res.data.edit_time, 0) + '</td></tr>\
								<tr><td align="right">确认时间：</td><td>' + windos.formatDate(res.data.confirm_time, 0) + '</td></tr>\
							<tbody>\
							</table>',
							btn1: function() {
								var value = res.data.status != 1 ? 1 : 0;
								windos.ajaxPost('/site/save', {id: res.data.id, field: 'status', value: value}, function(res2){
									//console.log(res2);
								});
								layer.closeAll();
								open = false;
							},
							btn2: function() {
								layer.closeAll();
								open = false;
							},
							btn3: function() {
								var value = res.data.status != 2 ? 2 : 0;
								windos.ajaxPost('/site/save', {id: res.data.id, field: 'status', value: value}, function(res2){
									//console.log(res2);
								});
								layer.closeAll();
								open = false;
							},
							success: function(layero) {
								var btn = layero.find('.layui-layer-btn');
								btn.find('.layui-layer-btn2').css({'background-color': '#FF5722', 'color': '#FFF'});
								open = true;
								
								$(document).bind('keyup', function(event) {
									var code = event.keyCode || event.which || event.charCode;
									if (code == 13 && open) {
										var value = res.data.status != 1 ? 1 : 0;
										windos.ajaxPost('/site/save', {id: res.data.id, field: 'status', value: value}, function(res2){
											//console.log(res2);
										});
										layer.closeAll();
										open = false;
									}
									
								});
								
								
							}
						});
					} else {
						layer.msg('无效的邀请码', {icon: 5});
					}
					//console.log(res);
				});
			} else {
				layer.msg('输入4位数邀请码', {icon: 5});
			}
			
		
		
	}).bind('focus', function() {
		var othis = $(this);
		othis.val('');
	}).bind('keyup', function(event) {
		var code = event.keyCode || event.which || event.charCode;
		if (code == 13) {
			$(this).trigger('blur');
		}
	});
	
	function formatStatus(code) {
		var res = '<span style="color:#F60">未验证</span>';
		switch(code) {
			case 1:
				res = '<span style="color:#0C0">已验证</span>';
			break;
			case 2:
				res = '<span style="color:#F00">已锁定</span>';
			break;
		}
		return res;
	}
});
	
</script>

<?php include('footer.php'); ?>

